import configparser
import os
import sys

def get_Path():
    path = os.path.split(os.path.realpath(__file__))[0]

    return path


path = get_Path()
config_path = os.path.join(path, 'config.ini')
config = configparser.ConfigParser()  # 调用外部的读取配置文件的方法

config.read(config_path, encoding='utf-8')


class ReadConfig():

    def get_Report(self, name):
        value = config.get('report', name)

        return value

    def get_Env(self, name):
        value = config.get('env', name)

        return value

    def get_Drive(self, name):
        value = config.get('drive', name)

        return value

    def get_Url(self, name):
        value = config.get('env', name)

        return value

    def get_User(self, name):
        value = config.get('user', name)

        return value

# print(      os.path.dirname(os.path.dirname(__file__))
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
#
# if sys.platform == "win32":
#     conf_dir = os.path.join(BASE_DIR, '/common/config.ini').replace('/', '\\')
# else:
#     conf_dir = os.path.join(BASE_DIR, '/common/config.ini')
#
#
# class Config(object):
#
#     def __init__(self, path):
#         self.path = path
#         self.cf = configparser.ConfigParser()
#         self.cf.read(self.path, encoding='utf-8')
#
#     def get(self, field, key):
#         print(2)
#         result = ""
#         try:
#             print(3)
#             result = self.cf.get(field, key)
#             print(4)
#             print(field)
#             print(key)
#         except:
#             result = ""
#         return result
#
#     def set(self, field, key, value):
#         try:
#             self.cf.set(field, key, value)
#             self.cf.write(open(self.path, 'w'))
#         except:
#             return False
#         return True
#
#
# def r_config(config_file_path, field, key):
#     rf = configparser.ConfigParser()
#     try:
#         rf.read(config_file_path, encoding='utf-8')
#         if sys.platform == "win32":
#             result = rf.get(field, key).replace('base_dir', str(BASE_DIR)).replace('/', '\\')
#         else:
#             result = rf.get(field, key).replace('base_dir', str(BASE_DIR))
#     except:
#         sys.exit(1)
#     return result
#
#
# def w_config(config_file_path, field, key, value):
#     wf = configparser.ConfigParser()
#     try:
#         wf.read(config_file_path)
#         wf.set(field, key, value)
#         wf.write(open(config_file_path, 'w'))
#     except:
#         sys.exit(1)
#     return True


# if __name__ == '__main__':
#     print(1)
#     # b = r_config(conf_dir, 'report', 'img_path')
#     # print(b)
#     print(ReadConfig().get_Report('log_path'))
#     print(BASE_DIR)
#     print(os.path.dirname(os.path.dirname(__file__)))